package com.onepiece.gen.generator.engine;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.util.Map;

public class MybatisPlusTemplateEngine extends VelocityTemplateEngine {

    public MybatisPlusTemplateEngine(){
    }
    @Override
    protected void outputCustomFile(@NotNull Map<String, String> customFile, @NotNull TableInfo tableInfo, @NotNull Map<String, Object> objectMap) {
        String entityName = tableInfo.getEntityName();
        String otherPath = this.getPathInfo(OutputFile.other);
        customFile.forEach((key, value) -> {
            String fileName = String.format(otherPath + File.separator + entityName  + "%s" + ".java", key);
            System.out.println( JSONUtil.parse(objectMap).toJSONString(1));
            this.outputFile(new File(fileName), objectMap, value);
        });
    }

}
